<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="tld" uri="/WEB-INF/tld/rei.tld" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@include file="/WEB-INF/include/admin-head.jsp" %>
<body>
<div class="ok-body">
	<!--模糊搜索区域-->
	<div class="layui-row">
		<form class="layui-form layui-col-md12 ok-search">
			<input class="layui-input" placeholder="账号" autocomplete="off" name="name">
			<button class="layui-btn" lay-submit="" lay-filter="search">
				<i class="layui-icon">&#xe615;</i>
			</button>
		</form>
	</div>
	<!--数据表格-->
	<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script><script src="/static/js/jquery.min.js"></script>
<script>
	layui.use(["element", "jquery", "table", "form", "laydate", "okLayer", "okUtils", "okMock"], function () {
		let table = layui.table;
		let form = layui.form;
		let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		let okMock = layui.okMock;
		let $ = layui.jquery;

		laydate.render({elem: "#startTime", type: "datetime"});
		laydate.render({elem: "#endTime", type: "datetime"});
		okLoading.close($);
		let userTable = table.render({
			elem: '#tableId',
			url: '/admin/investigation/list/data',
			limit: 20,
			page: true,
			toolbar: true,
			toolbar: "#toolbarTpl",
			size: "lg",
			cols: [[
			    	{type: "checkbox", fixed: "left"},
			    	
			    	
			                         
                        {field: "id", title: "序号", width: 160},
                    
               	        {field: "type", title: "事故类型", width: 100, templet: "#roleTpl"},
                    
                        {field: "reason", title: "事故原因", width: 160},
                    
                        {field: "drink", title: "是否酒驾", width: 160},
                    
                        {field: "carSelfReason", title: "车问题", width: 160},
                    
                        {field: "driver", title: "失误驾驶", width: 160},
                    
                        {field: "createDate", title: "调查时间", width: 160},
                    
                        {field: "orderId", title: "保单", width: 160},
			
				{title: "操作", width: 100, align: "center", fixed: "right", templet: "#operationTpl"}
			]],
			done: function (res, curr, count) {
				console.info(res, curr, count);
			}
		});

		form.on("submit(search)", function (data) {
			userTable.reload({
				where: data.field,
				page: {curr: 1}
			});
			return false;
		});

		table.on("toolbar(tableFilter)", function (obj) {
			switch (obj.event) {
				case "batchEnabled":
					batchEnabled();
					break;
				case "batchDisabled":
					batchDisabled();
					break;
				case "batchDel":
					batchDel();
					break;
				case "add":
					add();
					break;
			}
		});

		table.on("tool(tableFilter)", function (obj) {
			let data = obj.data;
			switch (obj.event) {
				case "edit":
					edit(data);
					break;
				case "del":
					del(data.id);
					break;
			}
		});


		function batchDel() {
			okLayer.confirm("确定要批量删除吗？", function (index) {
				let idsStr = okUtils.tableBatchCheck(table);
				if (idsStr) {
					  $.post("/admin/investigation/delete",{id: idsStr},function (result) {
					      if (result.code == 0){
					          layer.alert("删除成功！",{icon:1},function (index) {
					              location.reload();
					       })
					      }else {
					          layer.msg(result.message);
					      }
					  })
				}
			});
		}

		function add() {
			okLayer.open("添加", "/admin/investigation/add", "90%", "90%", null, function () {
				userTable.reload();
			})
		}

		function edit(data) {
			okLayer.open("更新", "/admin/investigation/diaocha?id="+data.orderId, "90%", "90%", function (layero) {
			}, function () {
				userTable.reload();
			})
		}

		function del(id) {
			okLayer.confirm("确定要删除吗？", function () {
				$.post("/admin/investigation/delete",{id: id},function (result) {
					if (result.code == 0){
						layer.alert("删除成功！",{icon:1},function (index) {
							location.reload();
						})
					}else {
						layer.msg(result.message);
					}
				})
			})
		}
	})
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDel">批量删除</button>
		<button class="layui-btn layui-btn-sm" lay-event="add">添加用户</button>
	</div>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
	<a href="javascript:" title="编辑" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
</script>

<script type="text/html" id="statusTpl">
	{{#  if(d.state == 0){ }}
	<span class="layui-btn layui-btn-normal layui-btn-xs">状态1</span>
	{{#  } else if(d.state == 1) { }}
	<span class="layui-btn layui-btn-normal layui-btn-xs">状态2</span>
	{{#  } else if(d.state == 2) { }}
	<span class="layui-btn layui-btn-normal layui-btn-xs">状态3</span>
	{{#  } else if(d.state == 3) { }}
	<span class="layui-btn layui-btn-warm layui-btn-xs">状态4</span>
	{{#  } }}
</script>
<script type="text/html" id="roleTpl">
	{{#  if(d.type == 0){ }}
	<span class="layui-btn layui-btn-normal layui-btn-xs">会员</span>
	{{#  } else if(d.type == 1) { }}
	<span class="layui-btn layui-btn-warm layui-btn-xs">老师</span>
	{{#  } else if(d.type == 2) { }}
	<span class="layui-btn layui-btn-warm layui-btn-xs">管理员</span>
	{{#  } }}
</script>
</body>
</html>

